package me.yangbajing.model

import org.squeryl.Schema

import yangbajing.persistence.SquerylEntrypoint._

object Entities extends Schema {
  val users = table[MUser]("user_")
  on(users)(entity =>
    declare(
      entity.email is unique
    ))

  val userPasswords = table[MUserPassword]("user_password_")

  val documents = table[MDocument]("document_")
  on(documents)(entity =>
    declare(
      entity.id is dbType("char(24)"),
      entity.content is dbType("text"),
      entity.slug is unique,
      entity.created_at is indexed
    ))

  val tags = table[MTag]("tag_")
  on(tags)(entity =>
    declare(
      entity.ref_id is dbType("char(24)")
    ))

  val categories = table[MCategory]("category_")
  on(categories)(entity =>
    declare(
      entity.id is dbType("char(24)"),
      entity.name is unique,
      entity.sort_by is indexed
    ))

  val comments = table[MComment]("comment_")
  on(comments)(entity =>
    declare(
      entity.id is dbType("char(24)"),
      entity.ref_id is(indexed, dbType("char(24)")),
      entity.ref_comment is(indexed, dbType("char(24)"))
    ))

  val favorites = table[MFavorite]("favorite_")
  on(favorites)(entity =>
    declare(
      entity.ref_id is dbType("char(24)")
    ))

  override def defaultLengthOfString: Int = 4096
}
